﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server_NhaSach.DataAccess.HelperLayer;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using System.Data;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class PhieuDieuChinhKhoDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
            set { _error = value; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertPDCKho(PhieuDieuChinhKhoDTO PDCK)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MaPDCK", PDCK.MaPDCK);
            par[1] = new SqlParameter("@NgayDieuChinh", PDCK.NgayDieuChinh);
            par[2] = new SqlParameter("@MaNVXuat", PDCK.MaNVXuat);
            par[3] = new SqlParameter("@MaNVNhan", PDCK.MaNVNhan);
            par[4] = new SqlParameter("@MaKhoXuat", PDCK.MaKhoXuat);
            par[5] = new SqlParameter("@MaKhoNhan", PDCK.MaKhoNhan);
            par[6] = new SqlParameter("@TongTien", PDCK.TongTien);
            try
            {
                helper.InsertQuery("sp_Insert_PhieuDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePDCKho(PhieuDieuChinhKhoDTO PDCK)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MaPDCK", PDCK.MaPDCK);
            par[1] = new SqlParameter("@NgayDieuChinh", PDCK.NgayDieuChinh);
            par[2] = new SqlParameter("@MaNVXuat", PDCK.MaNVXuat);
            par[3] = new SqlParameter("@MaNVNhan", PDCK.MaNVNhan);
            par[4] = new SqlParameter("@MaKhoXuat", PDCK.MaKhoXuat);
            par[5] = new SqlParameter("@MaKhoNhan", PDCK.MaKhoNhan);
            par[6] = new SqlParameter("@TongTien", PDCK.TongTien);
            try
            {
                helper.UpdateQuery("sp_Update_PhieuDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePDCKho(string MaPDCK)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaPDCK", MaPDCK);
            try
            {
                helper.DeleteQuery("sp_Delete_PhieuDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PDCKho()
        {
            helper = new Helper();
            DataSet ds_phieu = helper.SelectQuery("sp_LayDS_PhieuDieuChinhKho");
            return ds_phieu;
        }
        #endregion
    }
}